const { dbUrl } = require("../config/config.default");

const mongoose = require("mongoose");
// 连接mangodb数据库
mongoose.connect(dbUrl, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

const db = mongoose.connection;
// 连接失败
db.on("error", (err) => {
  console.log("连接失败", err);
});
// 连接成功
db.once("open", function () {
  console.log("连接成功");
});

//组织导出模型
module.exports = {
  User: mongoose.model("User", require("./user")),
  Article: mongoose.model("Article", require("./article")),
};
